package com.liujun.spring4.demo.aop.application.event;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author liujun
 * @version 0.0.1
 * @date 2018/09/15
 */
public class MailSender implements ApplicationContextAware {

  private ApplicationContext ctx;

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.ctx = applicationContext;
  }

  public void sendMail(String to) {
    System.out.println("模拟发送邮件....");
    MailSendEvent mse = new MailSendEvent(this.ctx, to);
    //向容器中的所有事件监听器发送事件
    ctx.publishEvent(mse);
  }

}
